/**
 * LetterY.java | Created on 30 08 2010
 */
package com.pacm.letter;

/**
 * The letter Y implementation
 *
 * @author Paul Augustine C. Mendoza
 */
public class LetterY extends AbstractLetter {

    public LetterY(int size) {
        super(size);
    }

    public void buildLetter() {
        String[][] matrix = getMatrix();
        for (int rowIndex = 0; rowIndex < matrix.length; rowIndex++) {
            String[] row = matrix[rowIndex];
            for (int colIndex = 0; colIndex < row.length; colIndex++) {
                if (isAfterMiddle(rowIndex)) {
                    markLowerHalf(rowIndex, colIndex);
                } else {
                    markUpperHalf(rowIndex, colIndex);
                }
            }
        }
    }

    private boolean isAfterMiddle(int rowIndex) {
        return (rowIndex > getMiddlePoint());
    }

    private void markUpperHalf(int rowIndex, int colIndex) {
        if ((rowIndex == colIndex) || (colIndex == (getMaxIndex() - rowIndex))) {
            setCharacterMark(rowIndex, colIndex);
        } else {
            setSpaceMark(rowIndex, colIndex);
        }
    }

    private void markLowerHalf(int rowIndex, int colIndex) {
        if (isMiddleOfRow(colIndex)) {
            setCharacterMark(rowIndex, colIndex);
        } else {
            setSpaceMark(rowIndex, colIndex);
        }
    }

    private boolean isMiddleOfRow(int colIndex) {
        return (colIndex == getMiddlePoint());
    }
}
